#include "qtoolgraphicsscene.h"
#include "qcurvetool.h"
QToolGraphicsScene::QToolGraphicsScene(QObject *parent)
    :QGraphicsScene(parent),currentTool(0),ToolDict()
{
}

QToolGraphicsScene::QToolGraphicsScene(const QRectF & sceneRect, QObject * parent )
    : QGraphicsScene(sceneRect,parent),currentTool(0),ToolDict()
{

}
QToolGraphicsScene::QToolGraphicsScene(qreal x, qreal y, qreal width, qreal height, QObject * parent )
    : QGraphicsScene(x,y,width,height,parent),currentTool(0),ToolDict()
{

}


QToolGraphicsScene::~QToolGraphicsScene()
{
    for(QMap<QString,QMyTool*>::iterator iter=ToolDict.begin();iter!=ToolDict.end();++iter)
        delete iter.value();
}


void QToolGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    QGraphicsScene::mouseDoubleClickEvent(mouseEvent);
    if(currentTool)
        currentTool->mouseDoubleClickEvent(mouseEvent);

}
void QToolGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    QGraphicsScene::mousePressEvent(mouseEvent);
    if(currentTool)
        currentTool->mousePressEvent(mouseEvent);

}
void QToolGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    QGraphicsScene::mouseMoveEvent(mouseEvent);
    if(currentTool)
        currentTool->mouseMoveEvent(mouseEvent);
}
void QToolGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
    if(currentTool)
        currentTool->mouseReleaseEvent(mouseEvent);
}
void QToolGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *contextMenuEvent)
{
    QGraphicsScene::contextMenuEvent(contextMenuEvent);
    if(currentTool)
        currentTool->contextMenuEvent(contextMenuEvent);
}

bool QToolGraphicsScene::AddTool(QString name,QMyTool * tool_pt)
{
    if(tool_pt)
    {
        ToolDict.insert(name,tool_pt);
        return true;
    }
    return false;
}

bool QToolGraphicsScene::SetCurrentTool(QString name)
{
    if(ToolDict.contains(name))
    {
        currentTool=ToolDict[name];
        return true;
    }
    return false;
}
